<?php
/**
 * Created by PhpStorm.
 * User: 王峥宇
 * Date: 2019-04-29
 * Time: 18:36
 */

namespace app\admin\model;


use think\Session;

class Shop extends BaseModel
{
    public function indentShop(){
        return $this->belongsTo('Indent','shopid','shopid');
    }


    public static function getShopUser(){
        $shopuser = self::paginate(12);
        return $shopuser;
    }

    public static function getShopIndent(){
        $indent = new Indent();
        $shopindent = $indent->where('shopid','neq',0  )->paginate(12);
        return $shopindent;
    }

    public static function getInsertUser(){
        $shopid = self::max('shopid');
        if($shopid == ''){
            $shid = 10000;
        }else{
            $shid=$shopid+1;
        }
        $phone=input('phone');
        $ph=self::where('phone',$phone)->find();
        if($ph==''){
            $data['phone']=$phone;
        }else{
            return 2;
        }
        $data['password'] = md5(input('u_pwd'));
        $data['username'] = input('username');
        $data['shopid'] = $shid;
        $data['createtime'] = date('Y-m-d H:i:s');
        $data['appkey'] = getShopChar();
        $insert = self::insert($data);
        if ($insert){
            return 1;
        }else{
            return 0;
        }
    }
    //锁定
    public static function suoding()
    {
        $shopid=input('shopid');
        $rs=self::where('shopid',$shopid)->find();
        if($rs['status']==1)
        {
            $status=0;
        }
        else
        {
            $status=1;
        }
        $xiu=self::where('shopid',$shopid)->update(['status'=>$status]);
        if($xiu)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }

}